import { likeDoctorAPI } from "@/services/consult"
import type { FollowType,DoctorType, KnowledgeType } from "@/types/consult"
import { ref } from "vue"



//点击关注
export const useFollow = (type:FollowType='doc') =>{
//创建loading响应式数据
const loading = ref(false)
 const  follow = async(item:DoctorType | KnowledgeType) => {
    loading.value = true
    //发送请求
    try {
        await likeDoctorAPI(item.id,type)
        item.likeFlag = item.likeFlag === 1 ? 0 : 1
        //finally是不管请求有没有成功，都会执行
    } finally {
    loading.value = false
    }
    } 
    return {loading,follow}
}